###########################################################
##################ANALYSIS SCRIPT 3 #######################
######### SALIENCE WITH EXOGENOUS VARIABLES ###############
###########################################################
###########################################################
################# ISSUE ANALYSES ##########################

load("Data/EP_debates_07062023.Rdata")
library(lme4)
library(texreg)
library(sjPlot)
library(sjstats)
library(fixest)
library(ggplot2)
library(ggeffects)
library(tidyverse)
### BEGIN BY CENTERING AND SCALING EVERYTHING

EP_debates$radical <- abs(EP_debates$lrgen - 5)
range(EP_debates$radical, na.rm = TRUE)

centFUN <- function(x) {
  x - mean(x, na.rm = TRUE)
}

result <- apply(EP_debates[,c(22:24, 27:71, 73:75, 77:107,117:118)], MARGIN = 2, FUN = centFUN)
result <- as.data.frame(result)


EP_eurobar_cent <- cbind(EP_debates[,-c(22:24, 27:71, 73:75, 77:107,117:118)], result)

rm(list=setdiff(ls(), "EP_eurobar_cent"))

EP_eurobar_cent$embed_dict_scale <- scale(EP_eurobar_cent$embed_dict)
EP_eurobar_cent$aut_dict_scale <- scale(EP_eurobar_cent$aut_dict)
EP_eurobar_cent$immi_dict_scale <- scale(EP_eurobar_cent$immi_dict)
EP_eurobar_cent$int_dict_scale <- scale(EP_eurobar_cent$int_dict)
EP_eurobar_cent$lrgen_scale <- scale(EP_eurobar_cent$lrgen)
EP_eurobar_cent$radical_scale <- scale(EP_eurobar_cent$radical)

EP_eurobar_cent$aut_sal <- scale(EP_eurobar_cent$mip_n_govdebt_ipol)
EP_eurobar_cent$immi_sal <- scale(EP_eurobar_cent$mip_n_immigration_ipol)


### LOAD MONTHLY ASYLUM STATS AS A PROXY FOR IMMIGRATION SALIENCE #####
library(naniar)
immi_stats <- readxl::read_xlsx("Data/eurostat_asylum.xlsx", sheet = 3) #AT and HU don't report for a long time
immi_stats <- immi_stats[-1,]
immi_stats <- immi_stats[ , colSums(is.na(immi_stats)) == 0]

immi_stats <- immi_stats %>% replace_with_na_all(condition = ~. == ":")
immi_stats <- immi_stats %>%
  mutate(across(everything(), as.character))
colnames(immi_stats)[1] <- "country"

immi_stats <- mutate(immi_stats,
                     country = case_when(country == "AT" ~ "Austria",
                                         country == "BE" ~ "Belgium",
                                         country == "BG" ~ "Bulgaria",
                                         country == "CY" ~ "Cyprus",
                                         country == "CZ" ~ "Czech Republic",
                                         country == "DE" ~ "Germany",
                                         country == "DK" ~ "Denmark",
                                         country == "EE" ~ "Estonia",
                                         country == "EL" ~ "Greece",
                                         country == "ES" ~ "Spain",
                                         country == "FI" ~ "Finland",
                                         country == "FR" ~ "France",
                                         country == "HR" ~ "Croatia",
                                         country == "HU" ~ "Hungary",
                                         country == "IE" ~ "Ireland",
                                         country == "IT" ~ "Italy",
                                         country == "LT" ~ "Lithuania",
                                         country == "LU" ~ "Luxembourg",
                                         country == "LV" ~ "Latvia",
                                         country == "MT" ~ "Malta",
                                         country == "NL" ~ "Netherlands",
                                         country == "PL" ~ "Poland",
                                         country == "PT" ~ "Portugal",
                                         country == "RO" ~ "Romania",
                                         country == "SE" ~ "Sweden",
                                         country == "SI" ~ "Slovenia",
                                         country == "SK" ~ "Slovakia",
                                         country == "UK" ~ "United Kingdom"))
immi_long <-  immi_stats %>% pivot_longer(!country, names_to = "year_month", values_to = "immi_stat")

EP_eurobar_cent$year_mon <- NULL
EP_eurobar_cent$year_month <- format(as.Date(EP_eurobar_cent$date), "%Y-%m")

EP_eurobar_immi <- left_join(EP_eurobar_cent, immi_long, by = c("country", "year_month"))

EP_eurobar_immi$immi_stat <- as.numeric(EP_eurobar_immi$immi_stat)
range(EP_eurobar_immi$immi_stat, na.rm = T)


### LOAD MONTHLY UNEMPLYMENT STATS AS A PROXY FOR ECONOMIC CRISIS SALIENCE #####

unemploy_stats <- read.csv("Data/eurostat_unemployment.csv")
unemploy_stats <- subset(unemploy_stats, unemploy_stats$INDIC == "Unemployment according to ILO definition - Total")
unemploy_stats <- subset(unemploy_stats, unemploy_stats$S_ADJ != "Seasonally adjusted data, not calendar adjusted data")
unemploy_stats[,c(3:5,7)] <- NULL
unemploy_stats <- unemploy_stats %>% replace_with_na_all(condition = ~. == ":")
unemploy_stats$TIME <- gsub("M", "-", unemploy_stats$TIME)

unemploy_stats <- mutate(unemploy_stats,
                         country = case_when(GEO == "Germany (until 1990 former territory of the FRG)" ~ "Germany",
                                             GEO == "Czechia" ~ "Czech Republic"))

unemploy_stats$country <- ifelse(is.na(unemploy_stats$country), unemploy_stats$GEO, unemploy_stats$country)
unemploy_stats$GEO <- NULL
colnames(unemploy_stats)[1:2] <- c("year_month", "unemploy_stat")
unemploy_stats$unemploy_stat <- as.numeric(unemploy_stats$unemploy_stat)

EP_eurobar_ext <- left_join(EP_eurobar_immi, unemploy_stats, by = c("country", "year_month"))

rm(list=setdiff(ls(), "EP_eurobar_ext"))

###################################################################################################################
########################## RUN 2-WAY FIXED EFFECTS REGRESSIONS ####################################################
###################################################################################################################
###################################################################################################################
EP_eurobar_ext$immi_stat_scale <- scale(EP_eurobar_ext$immi_stat) 
EP_eurobar_ext$unemploy_stat_scale <- scale(EP_eurobar_ext$unemploy_stat)

data_immi <- subset(EP_eurobar_ext, EP_eurobar_ext$date > "2012-01-01" & EP_eurobar_ext$date < "2016-01-01")


est1 <- feols(immi_dict_scale ~ challenge*immi_stat + lrgen_scale + EP_Coa + nat_opp + de_macro + de_civil + de_health + 
               de_agri + de_labour + de_edu + de_envi + de_energy + 
               de_immi + de_transport + de_law + de_welfare  + de_commerce +
               de_defense + de_techno + de_trade + de_intern + de_govern +
               de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5  | year + country, data = data_immi, cluster = "party_id")
summary(est1) 

est2 <- feols(immi_dict_scale ~ challenge*immi_stat + EP_Coa + nat_opp + lrgen_scale | year + country + debate , data = data_immi, cluster = "party_id")
summary(est2) 



data_aut <- subset(EP_eurobar_ext, EP_eurobar_ext$date > "2007-01-01" & EP_eurobar_ext$date < "2012-01-01")

est3 <- feols(aut_dict_scale ~ challenge*unemploy_stat + lrgen_scale + EP_Coa + nat_opp + de_macro + de_civil + de_health + 
               de_agri + de_labour + de_edu + de_envi + de_energy + 
               de_immi + de_transport + de_law + de_welfare  + de_commerce +
               de_defense + de_techno + de_trade + de_intern + de_govern +
               de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5  | year + country, data = data_aut, cluster = "party_id")
summary(est3) 


est4 <- feols(aut_dict_scale ~ challenge*unemploy_stat + lrgen_scale + nat_opp + EP_Coa | year + country + debate, data = data_aut, cluster = "party_id")
summary(est4) 



texreg(list(est3, est4, est1, est2),
       file = "tables/issues_ext_08062023.tex",
       include.ci = FALSE,
       stars = c(0.001, 0.01, 0.05, 0.1),
       custom.coef.map = list("challenge" = "Challenger",
                              "unemploy_stat" = "Monthly Unemployment",
                              "immi_stat" = "Monthly Arrival Refugees",
                              "challenge:unemploy_stat" = "Challenger * Monthly Unemployment",
                              "challenge:immi_stat" = "Challenger * Monthly Arrival Refugees",
                              "lrgen_scale" = "LR-Positions",
                              "EP_Coa" = "EP-Opposition",
                              "nat_opp" = "Nat. Opposition"),
       booktabs = TRUE,
       dcolumn = FALSE,
       custom.gof.rows = list("Topic Controls" = c("Yes", "No", "Yes", "No"),
                              "Year Fixed Effects" = c("Yes", "Yes", "Yes", "Yes"),
                              "Country Fixed Effects" = c("Yes", "Yes", "Yes", "Yes"),
                              "Debate Fixed Effects" = c("No", "Yes", "No", "Yes")),
       custom.model.names = c("Austerity", "Austerity", "Immigration", "Immigration"),
       custom.note = "%stars. Clustered Standard Errors (National Party) in Parentheses",
       digits = 2,
       caption = "The effect of changes in issue salience on issue emphasis")




###### REPEAT WITH MULTILEVEL MODEL ######

data_immi$immi_stat <- centFUN(data_immi$immi_stat)
data_immi$year <-as.factor(data_immi$year)

data_aut$unemploy_stat <- centFUN(data_aut$unemploy_stat)
data_aut$year <-as.factor(data_aut$year)

MLM1 <- lmer(immi_dict_scale ~ challenge*immi_stat + lrgen_scale + EP_Coa + nat_opp + de_macro + de_civil + de_health + 
                        de_agri + de_labour + de_edu + de_envi + de_energy + 
                        de_immi + de_transport + de_law + de_welfare  + de_commerce +
                        de_defense + de_techno + de_trade + de_intern + de_govern +
                        de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5 + year + as.factor(country) +  (1|mep_ids) + (1|party_id), data = data_immi, control = lmerControl(optimizer = "Nelder_Mead"))
texreg(MLM1) 

MLM2 <- lmer(aut_dict_scale ~ challenge*unemploy_stat + lrgen_scale + EP_Coa + nat_opp + de_macro + de_civil + de_health + 
               de_agri + de_labour + de_edu + de_envi + de_energy + 
               de_immi + de_transport + de_law + de_welfare  + de_commerce +
               de_defense + de_techno + de_trade + de_intern + de_govern +
               de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5 + year + as.factor(country) +  (1|mep_ids) + (1|party_id), data = data_aut, control = lmerControl(optimizer = "Nelder_Mead"))
texreg(MLM2)


texreg(list(MLM2, MLM1),
       file = "Tables/issues_ext_MLM_080623.tex",
       include.ci = FALSE,
       stars = c(0.001, 0.01, 0.05, 0.1),
       custom.coef.map = list("challenge" = "Challenger",
                              "unemploy_stat" = "Monthly Unemployment",
                              "immi_stat" = "Monthly Arrival Refugees",
                              "challenge:unemploy_stat" = "Challenger * Monthly Unemployment",
                              "challenge:immi_stat" = "Challenger * Monthly Arrival Refugees",
                              "radical_scale" = "Extreme Positions",
                              "EP_Coa" = "EP-Opposition",
                              "nat_opp" = "Nat. Opposition"),
       booktabs = TRUE,
       dcolumn = FALSE,
       custom.gof.rows = list("Topic Controls" = c("Yes", "Yes"),
                              "Year Fixed Effects" = c("Yes", "Yes"),
                              "Country Fixed Effects" = c("Yes", "Yes")),
       custom.model.names = c("Austerity", "Immigration"),
       custom.note = "%stars. Random Intercept for Parties and MEPs",
       digits = 2,
       caption = "The effect of changes in issue salience on issue emphasis")


#### PLOT INTERACTION EFFECTS

data_aut$chall_fact <- as.factor(ifelse(data_aut$challenge == 1, "Challenger", "Mainstream"))
data_immi$chall_fact <- as.factor(ifelse(data_immi$challenge == 1, "Challenger", "Mainstream"))

MLM1_plot <- lmer(immi_dict_scale ~ chall_fact*immi_stat + lrgen_scale + EP_Coa + nat_opp + de_macro + de_civil + de_health + 
               de_agri + de_labour + de_edu + de_envi + de_energy + 
               de_immi + de_transport + de_law + de_welfare  + de_commerce +
               de_defense + de_techno + de_trade + de_intern + de_govern +
               de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5 + year + as.factor(country) +  (1|mep_ids) + (1|party_id), data = data_immi, control = lmerControl(optimizer = "Nelder_Mead"))

MLM2_plot <- lmer(aut_dict_scale ~ chall_fact*unemploy_stat + lrgen_scale + EP_Coa + nat_opp + de_macro + de_civil + de_health + 
               de_agri + de_labour + de_edu + de_envi + de_energy + 
               de_immi + de_transport + de_law + de_welfare  + de_commerce +
               de_defense + de_techno + de_trade + de_intern + de_govern +
               de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5 + year + as.factor(country) +  (1|mep_ids) + (1|party_id), data = data_aut, control = lmerControl(optimizer = "Nelder_Mead"))
summary(MLM2_plot)

M1_plot <- plot_model(MLM1_plot, type = "emm",
                          terms = c("immi_stat", "chall_fact"),
                          title = "Marginal Effects of Immigration Salience",
                          axis.title = c("Immigration Salience (Monthly Arrival Asylum seekers)", "Immigration Emphasis \n (standardized and centered around 0)"),
                          colors = "bw",
                          legend.title = "Party",
                          ci.lvl = .95) +
  theme(text = element_text(size = 16))+
  theme_classic()
M1_plot

M2_plot <- plot_model(MLM2_plot, type = "emm",
                      terms = c("unemploy_stat", "chall_fact"),
                      title = "Marginal Effects of Austerity Salience",
                      axis.title = c("Austerity Salience (Precentage unemployed in Labour Force)", "Austerity Emphasis \n (standardized and centered around 0)"),
                      colors = "bw",
                      legend.title = "Party",
                      ci.lvl = .95) +
  theme(text = element_text(size = 16))+
  theme_classic()
M2_plot


obj_sal_plots <- gridExtra::grid.arrange(M1_plot, M2_plot, ncol = 2)
ggsave("Figures/obj_salience_plots_12022024.png",obj_sal_plots, width = 230, device = "png", height = 100, units = "mm", dpi=300, scale = 1.2)
### CODE CHECKED AND RUN 08.06.2023

#### ARE THERE DIFFERENCES BETWEEN LEFT AND RIGHT CHALLENGERS?

data_immi_left <- subset(data_immi, data_immi$lrgen < 0)
data_immi_right <- subset(data_immi, data_immi$lrgen > 0)



MLM_left <- lmer(immi_dict_scale ~ challenge*immi_stat_scale  + lrgen_scale + EP_Coa + nat_opp + de_macro + de_civil + de_health + 
               de_agri + de_labour + de_edu + de_envi + de_energy + 
               de_immi + de_transport + de_law + de_welfare  + de_commerce +
               de_defense + de_techno + de_trade + de_intern + de_govern +
               de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5 + year + as.factor(country) +  (1|mep_ids) + (1|party_id), data = data_immi_left, control = lmerControl(optimizer = "Nelder_Mead"))
texreg(MLM_left) 

MLM_right <- lmer(immi_dict_scale ~ challenge*immi_stat_scale  + lrgen_scale + EP_Coa + nat_opp + de_macro + de_civil + de_health + 
               de_agri + de_labour + de_edu + de_envi + de_energy + 
               de_immi + de_transport + de_law + de_welfare  + de_commerce +
               de_defense + de_techno + de_trade + de_intern + de_govern +
               de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5 + year + as.factor(country) +  (1|mep_ids) + (1|party_id), data = data_immi_right, control = lmerControl(optimizer = "Nelder_Mead"))
texreg(MLM_right)

texreg(list(MLM_left, MLM_right),
       file = "Tables/issues_ext_LR_120224.tex",
       include.ci = FALSE,
       stars = c(0.001, 0.01, 0.05, 0.1),
       custom.coef.map = list("challenge" = "Challenger",
                              "unemploy_stat" = "Monthly Unemployment",
                              "immi_stat_scale" = "Monthly Arrival Refugees",
                              "challenge:unemploy_stat" = "Challenger * Monthly Unemployment",
                              "challenge:immi_stat_scale" = "Challenger * Monthly Arrival Refugees",
                              "lrgen_scale" = "Left-Right Position",
                              "EP_Coa" = "EP-Opposition",
                              "nat_opp" = "Nat. Opposition"),
       booktabs = TRUE,
       dcolumn = FALSE,
       custom.gof.rows = list("Topic Controls" = c("Yes", "Yes"),
                              "Year Fixed Effects" = c("Yes", "Yes"),
                              "Country Fixed Effects" = c("Yes", "Yes")),
       custom.model.names = c("Among Left Parties", "Among Right Parties"),
       custom.note = "%stars. Random Intercept for Parties and MEPs",
       digits = 2,
       caption = "The effect of changes in issue salience on issue emphasis for parties on the left and the right")


data_aut_left <- subset(data_aut, data_aut$lrgen < 0)
data_aut_right <- subset(data_aut, data_aut$lrgen > 0)

MLM_left_aut <- lmer(aut_dict_scale ~ challenge*unemploy_stat_scale + lrgen_scale + EP_Coa + nat_opp + de_macro + de_civil + de_health + 
                   de_agri + de_labour + de_edu + de_envi + de_energy + 
                   de_immi + de_transport + de_law + de_welfare  + de_commerce +
                   de_defense + de_techno + de_trade + de_intern + de_govern +
                   de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5 + year + as.factor(country) +  (1|mep_ids) + (1|party_id), data = data_aut_left, control = lmerControl(optimizer = "Nelder_Mead"))
texreg(MLM_left_aut) 

MLM_right_aut <- lmer(aut_dict_scale ~ challenge*unemploy_stat_scale + lrgen_scale + EP_Coa + nat_opp + de_macro + de_civil + de_health + 
                    de_agri + de_labour + de_edu + de_envi + de_energy + 
                    de_immi + de_transport + de_law + de_welfare  + de_commerce +
                    de_defense + de_techno + de_trade + de_intern + de_govern +
                    de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5 + year + as.factor(country) +  (1|mep_ids) + (1|party_id), data = data_aut_right, control = lmerControl(optimizer = "Nelder_Mead"))
texreg(MLM_right_aut)

texreg(list(MLM_left_aut, MLM_right_aut),
       file = "Tables/aut_ext_LR_120224.tex",
       include.ci = FALSE,
       stars = c(0.001, 0.01, 0.05, 0.1),
       custom.coef.map = list("challenge" = "Challenger",
                              "unemploy_stat" = "Monthly Unemployment",
                              "immi_stat_scale" = "Monthly Arrival Refugees",
                              "challenge:unemploy_stat_scale" = "Challenger * Monthly Unemployment",
                              "challenge:immi_stat_scale" = "Challenger * Monthly Arrival Refugees",
                              "radical_scale" = "Extreme Positions",
                              "EP_Coa" = "EP-Opposition",
                              "nat_opp" = "Nat. Opposition"),
       booktabs = TRUE,
       dcolumn = FALSE,
       custom.gof.rows = list("Topic Controls" = c("Yes", "Yes"),
                              "Year Fixed Effects" = c("Yes", "Yes"),
                              "Country Fixed Effects" = c("Yes", "Yes")),
       custom.model.names = c("Among Left Parties", "Among Right Parties"),
       custom.note = "%stars. Random Intercept for Parties and MEPs",
       digits = 2,
       caption = "The effect of changes in issue salience on issue emphasis for parties on the left and the right")




est5 <- feols(immi_dict_scale ~ challenge*immi_stat_scale + lrgen_scale + EP_Coa + nat_opp + de_macro + de_civil + de_health + 
                de_agri + de_labour + de_edu + de_envi + de_energy + 
                de_immi + de_transport + de_law + de_welfare  + de_commerce +
                de_defense + de_techno + de_trade + de_intern + de_govern +
                de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5  | year + country, data = data_immi_right, cluster = "party_id")
summary(est5) 


est6 <- feols(immi_dict_scale ~ challenge*immi_stat_scale + EP_Coa + nat_opp + lrgen_scale | year + country + debate , data = data_immi_right, cluster = "party_id")
summary(est6) 



est7 <- feols(aut_dict_scale ~ challenge*unemploy_stat_scale + lrgen_scale + EP_Coa + nat_opp + de_macro + de_civil + de_health + 
                de_agri + de_labour + de_edu + de_envi + de_energy + 
                de_immi + de_transport + de_law + de_welfare  + de_commerce +
                de_defense + de_techno + de_trade + de_intern + de_govern +
                de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5  | year + country, data = data_aut_left, cluster = "party_id")
summary(est7) 


est8 <- feols(aut_dict_scale ~ challenge*unemploy_stat_scale + lrgen_scale + nat_opp + EP_Coa | year + country + debate, data = data_aut_left, cluster = "party_id")
summary(est8) 




texreg(list(est5, est6, est7, est8),
       file = "tables/issues_ext_LR_260424.tex",
       include.ci = FALSE,
       stars = c(0.001, 0.01, 0.05, 0.1),
       custom.coef.map = list("challenge" = "Challenger",
                              "unemploy_stat_scale" = "Monthly Unemployment",
                              "immi_stat_scale" = "Monthly Arrival Refugees",
                              "challenge:unemploy_stat_scale" = "Challenger * Monthly Unemployment",
                              "challenge:immi_stat_scale" = "Challenger * Monthly Arrival Refugees",
                              "lrgen_scale" = "LR-Positions",
                              "EP_Coa" = "EP-Opposition",
                              "nat_opp" = "Nat. Opposition"),
       booktabs = TRUE,
       dcolumn = FALSE,
       custom.gof.rows = list("Topic Controls" = c("Yes", "No", "Yes", "No"),
                              "Year Fixed Effects" = c("Yes", "Yes", "Yes", "Yes"),
                              "Country Fixed Effects" = c("Yes", "Yes", "Yes", "Yes"),
                              "Debate Fixed Effects" = c("No", "Yes", "No", "Yes")),
       custom.model.names = c("Immigration (right only)", "Immigration (right only)", "Austerity (left only)", "Austerity (left only)"),
       custom.note = "%stars. Clustered Standard Errors (National Party) in Parentheses",
       digits = 2,
       caption = "The effect of changes in issue salience on issue emphasis")



### CODE UPDATED IN RESPONSE TO JEPP REVIEWERS 12.02.2024


est1 <- feols(embed_dict_scale ~ challenge*immi_stat + lrgen_scale + EP_Coa + nat_opp |debate + year + country, data = data_immi, cluster = "party_id")
summary(est1) 

est2 <- feols(embed_dict_scale ~ challenge*immi_stat + EP_Coa + nat_opp + lrgen_scale + + de_macro + de_civil + de_health + 
                de_agri + de_labour + de_edu + de_envi + de_energy + 
                de_immi + de_transport + de_law + de_welfare  + de_commerce +
                de_defense + de_techno + de_trade + de_intern + de_govern +
                de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5 | year + country  , data = data_immi, cluster = "party_id")
summary(est2) 

est3 <- feols(embed_dict_scale ~ challenge*unemploy_stat + lrgen_scale + EP_Coa + nat_opp |debate + year + country, data = data_aut, cluster = "party_id")
summary(est3) 

est4<- feols(embed_dict_scale ~ challenge*unemploy_stat + EP_Coa + nat_opp + lrgen_scale + + de_macro + de_civil + de_health + 
                de_agri + de_labour + de_edu + de_envi + de_energy + 
                de_immi + de_transport + de_law + de_welfare  + de_commerce +
                de_defense + de_techno + de_trade + de_intern + de_govern +
                de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5 | year + country  , data = data_aut, cluster = "party_id")
summary(est4) 


MLM_1 <- lmer(embed_dict_scale ~ challenge*immi_stat + lrgen_scale + EP_Coa + nat_opp + de_macro + de_civil + de_health + 
                       de_agri + de_labour + de_edu + de_envi + de_energy + 
                       de_immi + de_transport + de_law + de_welfare  + de_commerce +
                       de_defense + de_techno + de_trade + de_intern + de_govern +
                       de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5 + year + as.factor(country) +  (1|mep_ids) + (1|party_id), data = data_immi, control = lmerControl(optimizer = "Nelder_Mead"))
texreg(MLM_1) 

MLM_2 <- lmer(embed_dict_scale ~ challenge*unemploy_stat + lrgen_scale + EP_Coa + nat_opp + de_macro + de_civil + de_health + 
                de_agri + de_labour + de_edu + de_envi + de_energy + 
                de_immi + de_transport + de_law + de_welfare  + de_commerce +
                de_defense + de_techno + de_trade + de_intern + de_govern +
                de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5 + year + as.factor(country) +  (1|mep_ids) + (1|party_id), data = data_aut, control = lmerControl(optimizer = "Nelder_Mead"))
texreg(MLM_2) 


htmlreg(list(MLM_1, MLM_2),
       file = "Tables/AE_salience.html",
       include.ci = FALSE,
       stars = c(0.001, 0.01, 0.05, 0.1),
       custom.coef.map = list("challenge" = "Challenger",
                              "unemploy_stat" = "Monthly Unemployment",
                              "immi_stat" = "Monthly Arrival Refugees",
                              "challenge:unemploy_stat" = "Challenger * Monthly Unemployment",
                              "challenge:immi_stat" = "Challenger * Monthly Arrival Refugees",
                              "radical_scale" = "Extreme Positions",
                              "EP_Coa" = "EP-Opposition",
                              "nat_opp" = "Nat. Opposition"),
       booktabs = TRUE,
       dcolumn = FALSE,
       custom.gof.rows = list("Topic Controls" = c("Yes", "Yes"),
                              "Year Fixed Effects" = c("Yes", "Yes"),
                              "Country Fixed Effects" = c("Yes", "Yes")),
       custom.model.names = c("Model 1", "Model 2"),
       custom.note = "%stars. Random Intercept for Parties and MEPs",
       digits = 2,
       caption = "The effect of changes in issue salience (exogenous measure) on anti-establishment rhetoric")


